package com.ddsfec.homepageapi.service;

import com.ddsfec.homepageapi.dao.HomepageDAO;
import com.ddsfec.homepageapi.entity.HomeGoodsVo;
import com.ddsfec.homepageapi.entity.ResultBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomepageService {

    @Resource
    HomepageDAO homepageDAO;

    public ResultBean seckillHomepage() {
        ResultBean<HomeGoodsVo> resultBean=new ResultBean();

        try{

            List<HomeGoodsVo> list = homepageDAO.seckillHomepage();
            resultBean.setData(list);

        }catch (Exception e){
            e.printStackTrace();
            resultBean.setCode(1000L);
            resultBean.setMsg("请求失败");
            return resultBean;
        }
        return resultBean;
    }

    public ResultBean homeGoodsAllType() {
        ResultBean resultBean=new ResultBean();

        try{
            Map<String,List<HomeGoodsVo>>map =new HashMap<>();
            List<HomeGoodsVo> seckillList = homepageDAO.seckillHomepage();
            List<HomeGoodsVo> healthList = homepageDAO.healthHomepage();
            map.put("seckillList",seckillList);
            map.put("healthList",healthList);

            resultBean.setBean(map);

        }catch (Exception e){
            e.printStackTrace();
            resultBean.setCode(1000L);
            resultBean.setMsg("请求失败");
            return resultBean;
        }
        return resultBean;
    }

}
